<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Register a function for execution on shutdown</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.get-defined-functions.html">get_defined_functions</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.register-tick-function.html">register_tick_function</a></div>
 <div class="up"><a href="ref.funchand.html">Function handling 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.register-shutdown-function" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">register_shutdown_function</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">register_shutdown_function</span> &mdash; <span class="dc-title">Register a function for execution on shutdown</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.register-shutdown-function-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>register_shutdown_function</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$parameter</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$...</code></span>
  ]] )</div>

  <p class="para rdfs-comment">
   Registers a <em><code class="parameter">callback</code></em> to be executed after script
   execution finishes or <span class="function"><a href="function.exit.html" class="function">exit()</a></span> is called.
  </p>
  <p class="para">
   Multiple calls to <span class="function"><strong>register_shutdown_function()</strong></span> can be
   made, and each will be called in the same order as they were registered.
   If you call <span class="function"><a href="function.exit.html" class="function">exit()</a></span> within one registered shutdown
   function, processing will stop completely and no other registered
   shutdown functions will be called.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.register-shutdown-function-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">callback</code></em></dt>

     <dd>

      <p class="para">
       The shutdown callback to register.
      </p>
      <p class="para">
       The shutdown callbacks are executed as the part of the request, so
       it&#039;s possible to send output from them and access output buffers.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">parameter</code></em></dt>

     <dd>

      <p class="para">
       It is possible to pass parameters to the shutdown function by passing
       additional parameters.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">...</code></em></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.register-shutdown-function-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>

 
 <div class="refsect1 errors" id="refsect1-function.register-shutdown-function-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   If the passed callback is not callable a <strong><code>E_WARNING</code></strong>
   level error will be generated.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.register-shutdown-function-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>4.1.0</td>
       <td>
        The shutdown functions are now called as a part of the request.
        In earlier versions under Apache, the registered shutdown functions
        were called after the request has been completed (including sending
        any output buffers), so it was not possible to send output to the
        browser using <span class="function"><a href="function.echo.html" class="function">echo</a></span> or
        <span class="function"><a href="function.print.html" class="function">print</a></span>, or retrieve the contents of any output
        buffers using <span class="function"><a href="function.ob-get-contents.html" class="function">ob_get_contents()</a></span>.
        Headers were also always already sent.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.register-shutdown-function-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5021">
    <p><strong>Example #1 <span class="function"><strong>register_shutdown_function()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">shutdown</span><span style="color: #007700">()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;This&nbsp;is&nbsp;our&nbsp;shutdown&nbsp;function,&nbsp;in&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;here&nbsp;we&nbsp;can&nbsp;do&nbsp;any&nbsp;last&nbsp;operations<br />&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;before&nbsp;the&nbsp;script&nbsp;is&nbsp;complete.<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'Script&nbsp;executed&nbsp;with&nbsp;success'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">register_shutdown_function</span><span style="color: #007700">(</span><span style="color: #DD0000">'shutdown'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.register-shutdown-function-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Working directory of the script can change inside the shutdown function
    under some web servers, e.g. Apache.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Shutdown functions will not be executed if the process is killed with a SIGTERM
    or SIGKILL signal. While you cannot intercept a SIGKILL, you can use <span class="function"><a href="function.pcntl-signal.html" class="function">pcntl_signal()</a></span>
    to install a handler for a SIGTERM which uses <span class="function"><a href="function.exit.html" class="function">exit()</a></span> to
    end cleanly.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.register-shutdown-function-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><a href="ini.core.html#ini.auto-append-file" class="link">auto_append_file</a></li>
    <li class="member"><span class="function"><a href="function.exit.html" class="function" rel="rdfs-seeAlso">exit()</a> - 输出一个消息并且退出当前脚本</span></li>
    <li class="member">The section on <a href="features.connection-handling.html" class="link">connection handling</a></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.get-defined-functions.html">get_defined_functions</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.register-tick-function.html">register_tick_function</a></div>
 <div class="up"><a href="ref.funchand.html">Function handling 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
